;(function(){      
      
    var router = [{
            idx:0,
            path: 'home',
            url: '../shouye.html',
        },{
            idx:1,
            path: 'find',
            url: '../find.html',
        },{
            idx:2,
            path: 'shequ',
            url: '../shequ.html',
        },{
            idx:3,
            path: 'wode',
            url: '../wode.html',
        },]

    //改变页面
    function display_page(url){
        $('#content').load(url)
    }

  $('.bottomLi').on('click',function(){
      var path = $(this).data('path');
      var idx=$(this).data('idx')
    //   console.log(path)
      for(var i in router){
          if(router[i].path == path){
              display_page(router[i].url);
              history.pushState(router[i].url,null,'#/'+router[i].path);
          }
      }
  })
  window.addEventListener('popstate',function(e){
      var url = e.state;
      display_page(url);
      
  });
  window.addEventListener('load',function(){
      var path = location.hash.slice(2) || '../shouye';
      console.log(path)
      for(var i in router){//刷新 加载
          console.log(1)
          if(router[i].path == path){
              display_page(router[i].url);    
              history.replaceState(router[i].url,null,'#/' + path);        
              break;   
          }
          if(i == router.length-1){//重定向
              display_page(router[0].url);    
              history.replaceState(router[0].url,null,'#/' + router[0].path);    
          }
      }                        
  });

})();